/*
 *@Author: 张楚
 *@Date: 2021-08-04 10:14:43
 *@Description: 商品分类页面
*/
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:totaldemo/utils/util.dart';

class ShopHomePage extends StatefulWidget {
  const ShopHomePage({Key key}) : super(key: key);

  @override
  _ShopHomePageState createState() => _ShopHomePageState();
}

class _ShopHomePageState extends State<ShopHomePage>
    with TickerProviderStateMixin {
  TabController _tabc;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabc = TabController(length: 4, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('商品列表'),
        centerTitle: true,
        bottom: TabBar(
          controller: _tabc,
          tabs: [
            Tab(
              text: '分类',
            ),
            Tab(
              text: '分类',
            ),
            Tab(
              text: '分类',
            ),
            Tab(
              text: '分类',
            ),
          ],
        ),
      ),
      body: TabBarView(controller: _tabc, children: [
        shopItemPage(),
        shopItemPage(),
        shopItemPage(),
        shopItemPage()
      ]),
      floatingActionButton:
          FloatingActionButton.extended(onPressed: () {}, label: Text('data')),
    );
  }

  Widget shopItemPage() {
    return ListView.builder(
        itemCount: 30,
        itemBuilder: (BuildContext context, int index) {
          return shopItemWidget();
        });
  }

  Widget shopItemWidget() {
    return Container(
      padding: EdgeInsets.only(top: 10),
      margin: EdgeInsets.all(14),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          ///左侧图片
          Container(
            margin: EdgeInsets.only(right: 10),
            child: Image.asset(
              Util.getUrl('shopping.png'),
              width: 100,
              height: 100,
            ),
          ),

          ///右侧文字
          Expanded(
            child: Column(
              // mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text('标题'),
                Text('内容'),
                Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    TextButton(onPressed: () {}, child: Text('加入购物车'))
                  ],
                )
              ],
            ),
          )
        ],
      ),
    );
  }
}
